package com.ekuaitu.kuaitu.map;

import android.graphics.Color;

import com.amap.api.location.DPoint;
import com.amap.api.maps.AMap;
import com.amap.api.maps.model.Circle;
import com.amap.api.maps.model.CircleOptions;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Polygon;
import com.amap.api.maps.model.PolygonOptions;
import com.ekuaitu.kuaitu.bean.CityDetailBean;
import com.ekuaitu.kuaitu.bean.RedPacketHotListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Michael Pi on 2016/12/8.
 */

public class PolylineBoundUtils {
    private AMap aMap;
    private Polygon polygon;
    private static final int STROKE_COLOR = Color.argb(70, 3, 145, 255);
    private static final int FILL_COLOR = Color.argb(20, 0, 0, 180);
    private Circle mCircle;

    public PolylineBoundUtils() {
    }

    public PolylineBoundUtils(AMap aMap) {
        this.aMap = aMap;
    }

    public Polygon addBoundAndCoverToMap(List<LatLng> redBikeBound) {
        return aMap.addPolygon(new PolygonOptions().addAll(redBikeBound).fillColor(Color.parseColor("#22FA960A")).strokeColor(Color.parseColor("#FA960A")).strokeWidth(6));
    }


    public List<Polygon> addBoundsToMap(List<CityDetailBean.AttachmentBean.EnclosureBean.BikeRangeListBean> bikeRangeList) {
        List<Polygon> polygonList = new ArrayList<>();
        for (int i = 0; i < bikeRangeList.size(); i++) {
            polygonList.add(aMap.addPolygon(new PolygonOptions().addAll(createBound(bikeRangeList.get(i).getBikeRange())).fillColor(Color.parseColor("#00000000")).strokeColor(Color.parseColor("#FA960A")).strokeWidth(6)));
        }
        return polygonList;
    }


    public List<Polygon> addCoversToMap(List<CityDetailBean.AttachmentBean.EnclosureBean.BikeRangeListBean> bikeRangeList) {
        List<Polygon> polygonList = new ArrayList<>();
        for (int i = 0; i < bikeRangeList.size(); i++) {
            polygonList.add(aMap.addPolygon(new PolygonOptions().addAll(createBound(bikeRangeList.get(i).getBikeRange())).fillColor(Color.parseColor("#22FA960A")).strokeColor(Color.parseColor("#00000000")).strokeWidth(0)));
        }
        return polygonList;
    }

    private List<LatLng> createBound(List<CityDetailBean.AttachmentBean.EnclosureBean.BikeRangeListBean.BikeRangeBean> bikeRange) {
        List<LatLng> boundList = new ArrayList<>();
        for (int i = 0; i < bikeRange.size(); i++) {
            LatLng latLng = new LatLng(bikeRange.get(i).getLat(), bikeRange.get(i).getLng());
            boundList.add(latLng);
        }
        return boundList;
    }

    /**
     * 电子围栏数据
     *
     * @param fencePoints
     * @return
     */
    private List<DPoint> createGeofenceInfos(List<RedPacketHotListBean.GeoFence.FencePoint> fencePoints) {
        List<DPoint> boundList = new ArrayList<>();
        for (int i = 0; i < fencePoints.size(); i++) {
            DPoint dPoint = new DPoint(fencePoints.get(i).getLatitude(), fencePoints.get(i).getLongitude());
            boundList.add(dPoint);
        }
        return boundList;
    }

    public Circle addCircle(LatLng latlng, double radius) {
        CircleOptions options = new CircleOptions();
        options.strokeWidth(3f);
        options.fillColor(FILL_COLOR);
        options.strokeColor(STROKE_COLOR);
        options.center(latlng);
        options.radius(radius);
        return aMap.addCircle(options);
    }
}
